﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using G.Controls;
using Microsoft.Phone.Controls;

namespace FY13.View
{
    public partial class BrowserImageChildwindow : ChildWindow
    {
        public BrowserImageChildwindow(ImageSource source)
        {
            InitializeComponent();
            this.img.Source = source;
        }
        private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
        {
            initialAngle = transform.Rotation;
            initialScale = transform.ScaleX;
        }
        double initialAngle;
        double initialScale;
        private void OnPinchDelta(object sender, PinchGestureEventArgs e)
        {
            this.transform.CenterX = this.grid.ActualWidth / 2;
            this.transform.CenterY = this.grid.ActualHeight / 2;
            //transform.Rotation = initialAngle + e.TotalAngleDelta;
            transform.ScaleX = transform.ScaleY = initialScale * e.DistanceRatio;
        }

        private void OnPinchCompleted(object sender, PinchGestureEventArgs e)
        {

        }
        private void OnDragStarted(object sender, DragStartedGestureEventArgs e)
        {

        }

        private void OnDragDelta(object sender, DragDeltaGestureEventArgs e)
        {
            transform.TranslateX += e.HorizontalChange;
            transform.TranslateY += e.VerticalChange;
        }

        private void OnDragCompleted(object sender, DragCompletedGestureEventArgs e)
        {

        }
        private void OnDoubleTap(object sender, Microsoft.Phone.Controls.GestureEventArgs e)
        {
            if (this.transform.ScaleX != 1 || this.transform.ScaleY != 1)
            {

                this.transform.ScaleX = this.transform.ScaleY = 1;
                transform.TranslateX = transform.TranslateY = 0;
                transform.Rotation = 0;
            }
            else
            {
                this.transform.ScaleX = this.transform.ScaleY = 2;
                transform.Rotation = 0;
            }

        }
    }
}
